package com.itheima.server.interceptor;

import com.itheima.model.vo.ErrorResult;
import com.itheima.server.exception.BusinessException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/*异常处理类*/
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    public ResponseEntity ExceptionHandler(Exception ex){
        ex.printStackTrace();
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ErrorResult.error());//HttpStatus.INTERNAL_SERVER_ERROR就是枚举500
    }

    @ExceptionHandler(BusinessException.class)
    public ResponseEntity BusinessExceptionHandler(BusinessException be){
        be.printStackTrace();
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(be.getErrorResult());
    }
}
